package com.qf.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/code")
public class CodeController extends BaseServlet{
    /**
     * 生成验证码
     * @param request
     * @param response
     * @throws Exception
     */
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws Exception{
//        创建验证码工具类
        ValidateCode validateCode = new ValidateCode(100, 30, 4, 10);
//        获取验证码字符串内容
        String code = validateCode.getCode();
//        将验证码字符串内容保存在tomcat的session会话对象中，供之后校验使用
        request.getSession().setAttribute("code", code);
//        将验证码图片通过流写回到页面展示
        validateCode.write(response.getOutputStream());
    }

}
